package com.qf.commons.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import java.util.List;

/**
 * description: 架构层 - Web拦截器注册类
 * author: Ken
 * 公众号：Java架构栈
 */
public class WebIntercepterConfig implements WebMvcConfigurer {

    @Autowired(required = false)
    private List<HandlerInterceptorAdapter> interceptorAdapterList;

    /**
     * 添加拦截器的方法
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (interceptorAdapterList != null) {
            for (HandlerInterceptorAdapter handlerInterceptorAdapter : interceptorAdapterList) {
                registry.addInterceptor(handlerInterceptorAdapter);
            }
        }
    }
}
